using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Dogfight2008
{
  public class ValueEquals
  {
    public static bool AreEqual(object o1, object o2)
    {
      Type o1type = o1.GetType();
      Type o2type = o2.GetType();
      FieldInfo[] fields1 = o1type.GetFields(BindingFlags.NonPublic | BindingFlags.Public);
      FieldInfo[] fields2 = o2type.GetFields(BindingFlags.NonPublic | BindingFlags.Public);

      for (int i = 0; i < fields1.Length; i++)
      {
        FieldInfo fi = fields1[i];
        object box1 = fi.GetValue(o1);
        object box2 = fi.GetValue(o2);
        if(fi.FieldType.IsPrimitive)
        {
          if(!box1.Equals(box2))
            return false;
        }
        else {
          bool result = AreEqual(box1, box2);
          if(result==false)
            return false;
        }
      }
      return true;
    }
  }
}
